<?php

namespace App\Job\Delay;

use App\Actions\PaycallAction;
use App\Utils\LoggerUtil;
use Hyperf\AsyncQueue\Job;

class CallExitRoomDelayQueueJob extends Job
{
    private mixed $params;

    public function __construct($params)
    {
        // 这里最好是普通数据，不要使用携带 IO 的对象，比如 PDO 对象
        $this->params = $params;
    }


    public function handle()
    {
        // TODO: Implement handle() method.
        $body = json_decode($this->params, true);
        LoggerUtil::write("call_exit_room_queue_job", $body);
        $param = $body['param'];
        $res = $this->checkCallExitRoom(...$param);
        LoggerUtil::write("call_exit_room_queue_job", compact('res'));
    }

    /**
     * 检测到用户退出房间，
     * @param $call_id
     * @param $uid
     * @return bool
     */
    public function checkCallExitRoom($call_id, $uid)
    {
        try {
            (new PaycallAction())->noticeOtherHangUp($call_id, $uid);
            return true;
        } catch (\Throwable $e) {
            LoggerUtil::write("call_exit_room_queue_job", [$e->getMessage(), $e->getFile(), $e->getLine()]);
            return false;
        }
    }


}